package com.hnhcyy.goods.search;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hnhcyy.goods.service.GoodsService;
import com.hnhcyy.goods.service.SearchService;

@RestController
@RequestMapping("/search/goods")
public class GoodsSearchController {

	@Autowired SearchService searchService;

	@RequestMapping("/get")
	public HashMap get(int sjid,String spid) {
		return searchService.elget(sjid,spid);
	}

	@RequestMapping("/set")
	public boolean set(int sjid,String spid) {
		return searchService.elset(sjid,spid);
	}

	@RequestMapping("/setall")
	public String setall() {		
		long startTime=System.currentTimeMillis();//记录开始时间

		searchService.elsetall();

		long endTime=System.currentTimeMillis();//记录结束时间
		float excTime=(float)(endTime-startTime)/1000;
		System.out.println("setall spend times:"+excTime+"s");		
		return "setall spend times:"+excTime+"s";
	}

	@RequestMapping("/del")
	public boolean del(int sjid,String spid){
		try {
			return searchService.eldel(sjid,spid);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}

	@RequestMapping("/firstpage")
	public List<HashMap> firstpage(int sjid,int qyid,String dwbh,int lbid,int rows){
		long startTime=System.currentTimeMillis();//记录开始时间
		List<HashMap> list = searchService.firstpage(sjid,qyid,dwbh,lbid,rows);
		long endTime=System.currentTimeMillis();//记录结束时间
		float excTime=(float)(endTime-startTime)/1000;
		System.out.println("index page times:"+excTime+"s");		
		return list;
	}

	@RequestMapping("/firstpagetest")
	public String firstpagetest(){
		long startTime=System.currentTimeMillis();//记录开始时间
		searchService.firstpage(1,18,"TESTDW00003",107,8);
		searchService.firstpage(1,18,"TESTDW00003",121,8);
		searchService.firstpage(1,18,"TESTDW00003",101,8);
		searchService.firstpage(1,18,"TESTDW00003",108,8);
		searchService.firstpage(1,18,"TESTDW00003",109,8);
		searchService.firstpage(1,18,"TESTDW00003",2,8);
		long endTime=System.currentTimeMillis();//记录结束时间
		float excTime=(float)(endTime-startTime)/1000;
		System.out.println("firstpagetest spend times:"+excTime+"s");		
		return "firstpagetest spend times:"+excTime+"s";
	}

	@RequestMapping("/searchall")
	public HashMap searchall(){
		long startTime=System.currentTimeMillis();//记录开始时间
		HashMap list = searchService.searchall(1,18,"TESTDW00003",640,10);
		long endTime=System.currentTimeMillis();//记录结束时间
		float excTime=(float)(endTime-startTime)/1000;
		System.out.println("firstpagetest spend times:"+excTime+"s");		
		return list;
	}

	@RequestMapping("/searchallcount")
	public List<HashMap> searchallcount(){
		long startTime=System.currentTimeMillis();//记录开始时间
		List<HashMap> list = searchService.searchallcount(1,18,"TESTDW00003",10,10);
		long endTime=System.currentTimeMillis();//记录结束时间
		float excTime=(float)(endTime-startTime)/1000;
		System.out.println("firstpagetest spend times:"+excTime+"s");		
		return list;
	}
}
